package model

import (
	"api_gateway/global"
	"gorm.io/gorm"
	"time"
)

type TestPaper struct {
	Id              uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	PaperType       uint           `gorm:"column:paper_type;type:bigint;comment:类型：1.手动 2.自动;not null;" json:"paper_type"`                // 类型：1.手动 2.自动
	PaperName       string         `gorm:"column:paper_name;type:varchar(20);comment:试卷名称;not null;" json:"paper_name"`                   // 试卷名称
	PaperTime       string         `gorm:"column:paper_time;type:varchar(20);comment:考试时长;not null;" json:"paper_time"`                   // 考试时长
	ArrangementType uint           `gorm:"column:arrangement_type;type:bigint;comment:顺序类型: 1.随机 2.顺序;not null;" json:"arrangement_type"` // 顺序类型: 1.随机 2.顺序
	OptionType      uint           `gorm:"column:option_type;type:bigint;comment:选项类型: 1.随机 2.顺序;not null;" json:"option_type"`           // 选项类型: 1.随机 2.顺序
	Score           uint           `gorm:"column:score;type:bigint;comment:分数;not null;" json:"score"`                                    // 分数
	PassingScore    uint           `gorm:"column:passing_score;type:bigint;comment:及格分数;not null;" json:"passing_score"`                  // 及格分数
	Reviewer        string         `gorm:"column:reviewer;type:varchar(20);comment:阅卷人;not null;" json:"reviewer"`                        // 阅卷人
	Known           string         `gorm:"column:known;type:varchar(20);comment:考试须知;not null;" json:"known"`                             // 考试须知
	SingleScore     uint           `gorm:"column:single_score;type:bigint;comment:单选题分数;not null;" json:"single_score"`                   // 单选题分数
	CreatedAt       time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt       time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt       gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (t *TestPaper) TableName() string {
	return "test_paper"
}

func (t *TestPaper) Create() error {
	return global.DB.Create(&t).Error
}

func (t *TestPaper) Del(id uint) error {
	return global.DB.Where("id=?", id).Delete(&t).Error
}

func (t *TestPaper) List() (list []*TestPaper, err error) {
	err = global.DB.Find(&list).Error
	if err != nil {
		return nil, err
	}
	return
}

func (t *TestPaper) Info(paper_name string) error {
	return global.DB.Where("paper_name=?", paper_name).Limit(1).First(&t).Error
}
